#include "Ui.h"


LRESULT WindowProcedure(HWND hwnd, unsigned int msg, WPARAM wp, LPARAM lp) {
	HDC         hdc;
	PAINTSTRUCT ps;
	switch(msg) {
		case WM_DESTROY:
			printf("\ndestroying window\n");
			PostQuitMessage(0) ;
			return 0L ;

		case WM_LBUTTONDOWN:
			printf("\nmouse left button down at (%d, %d)\n", LOWORD(lp), HIWORD(lp));
		case WM_PAINT:
			//hdc = BeginPaint(hwnd, &ps);                              //1

			//HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0));         //2
			//HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,hBrush);      //3

			//Rectangle(hdc, 50, 50, 200, 200);                         //4

			//SelectObject(hdc, hOldBrush);                             //5
			//DeleteObject(hBrush);

			//EndPaint(hwnd, &ps);                                      //6
			//cout<<"aaaa\n";
			break;


		// fall thru
		default:
			return DefWindowProc( hwnd, msg, wp, lp ) ;
	}
}
Ui::Ui(Pipe * pipe) {

	const char* const myclass = "myclass" ;

	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	/* Win 3.x */
	wc.style = CS_DBLCLKS;
	wc.lpfnWndProc = WindowProcedure;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = GetModuleHandle(0);
	wc.hIcon = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName = 0;
	wc.lpszClassName = myclass;
	/* Win 4.0 */
	wc.hIconSm = LoadIcon(0, IDI_APPLICATION);

	if(RegisterClassEx(&wc)) {
		MyRect rect;
		rect.x = 0;
		rect.y = 0;
		rect.width = 480;
		rect.height = 540;

		HWND hWnd = CreateWindowEx( WS_EX_LAYERED, myclass, "title",
		                            WS_OVERLAPPEDWINDOW, rect.x, rect.y,
		                            rect.width, rect.height, 0, 0, GetModuleHandle(0), 0 ) ;

		
		
		// 设置窗口透明度
		SetLayeredWindowAttributes(
		    hWnd,       // 窗口句柄
		    RGB(255, 255, 255),          // 颜色键
		    0,        // 透明度，取值为0-255
		    LWA_COLORKEY   //
		);

		SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		if(hWnd) {
			ShowWindow( hWnd, SW_SHOWDEFAULT ) ;
			MSG msg ;
			while( GetMessage( &msg, 0, 0, 0 ) ) DispatchMessage(&msg);
		}
	
	}
}

Ui::~Ui() {
}